package com.junzhiit.nengji.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.bo.ChainGoodsSkuItemsBO;
import com.junzhiit.nengji.bo.GoodsSkuBO;
import com.junzhiit.nengji.dao.ChainGoodsSkuItemsDAO;
import com.junzhiit.nengji.model.ChainGoodsSkuItems;

@Repository
public class ChainGoodsSkuItemsDAOImpl extends AbstractBaseDAO<ChainGoodsSkuItems> implements ChainGoodsSkuItemsDAO{

	@Override
	public List<GoodsSkuBO> queryGoodsSku(String shopId) {
		StringBuffer sql = new StringBuffer();
		sql.append(" select cu.id uid,u_item.*");
		sql.append(" from chain_sku cu inner join chain_sku_items csi on csi.chain_sku_id=cu.id");
		sql.append(" where cu.shop_id=? and csi.is_delete=? and cu.is_delete=?");
		sql.append(" order by cu.created_time desc");

		StatementParameter param = new StatementParameter();
		param.setString(shopId);
		param.setInt(IsDelete.NO.toIntValue());
		param.setInt(IsDelete.NO.toIntValue());

		return queryForList(sql.toString(), GoodsSkuBO.class, param);

	}
	
	@Override
	public List<ChainGoodsSkuItems> queryGoodsSkuItems(String chainGoodsId) {
		String sql = "select * from chain_goods_sku_items where is_delete=? and chain_goods_id=? order by created_time desc";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(chainGoodsId);

		return queryForList(sql, ChainGoodsSkuItems.class, param);
	}
	
	@Override
	public List<ChainGoodsSkuItemsBO> queryGoodsSkuItemsBO(String chainGoodsId){
		StringBuffer sql=new StringBuffer();
		sql.append(" select cgsi.chain_sku_id,cgsi.chain_sku_items_id,csi.standard,cs.`name`");
		sql.append(" from chain_goods_sku_items cgsi");
		sql.append(" inner join chain_sku cs on cs.id=cgsi.chain_sku_id");
		sql.append(" inner join chain_sku_items csi on csi.id=cgsi.chain_sku_items_id");
		sql.append(" where cgsi.chain_goods_id=?");
		sql.append(" order by cgsi.sort asc,cgsi.sku_items_sort asc");
		
		StatementParameter param=new StatementParameter();
		param.setString(chainGoodsId);
		
		return super.queryForList(sql.toString(), ChainGoodsSkuItemsBO.class,param);
	}

	@Override
	public boolean deleteGoodsSkuItems(String chainGoodsId) {

		String sql = "delete from chain_goods_sku_items where is_delete=? and chain_goods_id=? order by created_time desc";

		StatementParameter param = new StatementParameter();
		param.setInt(IsDelete.NO.toIntValue());
		param.setString(chainGoodsId);

		return updateForBoolean(sql, param);
	}
	
}
